package pl.iachoo.ctl.tabory.dao.hibernate.services;

import java.io.Serializable;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Example;

public abstract class BaseDaoService<T extends Serializable> {

	private final Logger log = Logger.getLogger(BaseDaoService.class);

	protected SessionFactory sessionFactory;

	public BaseDaoService(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	// protected T update(T persistanceInstance) {
	// log.debug("Updating: " + persistanceInstance.toString());
	// try {
	// session.beginTransaction();
	// session.update(persistanceInstance);
	// session.getTransaction().commit();
	// log.debug("Update OK.");
	// } catch (Exception e) {
	// log.error(e.getMessage(), e);
	// }
	// return persistanceInstance;
	// }
	//
	// protected T save(T persistentInstance) {
	// log.debug("Saving: " + persistentInstance);
	// try {
	// session.beginTransaction();
	// session.save(persistentInstance);
	// session.getTransaction().commit();
	// log.debug("Save OK.");
	// } catch (Exception e) {
	// log.error("Save or update failed. ", e);
	// }
	// return persistentInstance;
	// }
	//
	// protected void delete(T persistentInstance) {
	// log.debug("Deleting persistentInstance: " + persistentInstance);
	// try {
	// session.beginTransaction();
	// session.delete(persistentInstance);
	// session.getTransaction().commit();
	// log.error("Delete OK.");
	// } catch (Exception e) {
	// log.error("Delete failed. ", e);
	// }
	// }
	//
	// @SuppressWarnings("unchecked")
	// protected T findById(Class<T> clazz, long id) {
	// log.debug("Find by ID with id: " + id);
	// T result = null;
	// try {
	// session.beginTransaction();
	// result = (T) session.load(clazz, id);
	// session.getTransaction().commit();
	// log.debug("Find by ID result: " + result);
	// } catch (Exception e) {
	// log.error("Load faild. ", e);
	// }
	// return result;
	// }
	//
	// @SuppressWarnings("unchecked")
	// protected List<T> findByCriteria(Class<T> clazz, Object criterion) {
	// log.debug("Find by criteria with criterion: " + criterion.toString());
	// List<T> result = null;
	// try {
	// session.beginTransaction();
	// result = session.createCriteria(clazz)
	// .add(Example.create(criterion)).list();
	// session.getTransaction().commit();
	// log.debug("Find by criteria result: " + result.toString());
	// } catch (Exception e) {
	// log.error("Load faild. ", e);
	// }
	// return result;
	//
	// }

}
